<script type="text/javascript">
    var FixGroups = {{json_encode($Data["FixGroups"])}};
    function jqxFixColumns(columns){
        try{
        columns['GroupName'].createeditor=function (row, cellvalue, editor) {
                var dataSource = {{json_encode($Data["groups"])}};//['Group A', 'Group B', 'Group C','Group D','Group E'];
                editor.jqxDropDownList({source: dataSource });
        }
        }catch(e){tipMessage(e.message);}
        return columns;
    }
    function handleEvent_jqxGrid(jqxgrid){
        jqxgrid.bind('cellendedit', function (event) {
            try{
                var args = event.args;
                var Column = args.datafield ,Row = args.rowindex,Value = args.value;
                var Data=jqxgrid.jqxGrid('getrowdata', Row);
                var ID=Data.ID;
                if(ID==undefined || ID==""){
                    return;
                }
                switch(Column){
                    case "GroupName":
                        Value=FixGroups[Value];
                        //alert(Value);return;
                        ChangeGroup(ID,Value);
                        break;
                    default:
                        tipMessage("Unkown this cell. Maybe 'editable' of this colums is 'off'"); 
                }
            }catch(e){
                tipMessage(e.message);
                console.log("Error:"+e.message);
            }
        });
    }
    function ChangeGroup(ID,Group){
        try{
            var url,data;
            url="{{base_url()}}APanel/customer/ChangeGroup";
            data={
                ID      :   ID,
                Group  :   Group
            }
            isrunning=true;
            jqxAjax(url,data,function(result){
                isrunning=false;
                if(result.code>=0){
                    myjqxGrid.Refresh();
                }else{
                    tipMessage(result.msg);
                }
            });
            
        }catch(e){
            console.log("JSON Error:"+e.message+"\n↵ Error");
            tipMessage(e.message);
            //ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
        }
    }
</script>